import {Component,createRef} from 'react'
import {Form,Input, Button} from 'antd'
export default class Search extends Component{
    constructor(props) {
        super(props);
        this.state = {
            ...this.props
        }
        this.form = createRef()
    }
    handleReset = ()=>{
        this.form.current.resetFields()
    }
    render() {
        const { list } = this.state
        return(
            <>
                <Form
                    layout='inline'
                    onFinish={(e)=>{this.state.search(e)}}
                    ref={this.form}
                >
                    {
                        list && list.map(e=>{
                            switch (e.type) {
                                case 'Input':
                                    console.log(e)
                                    return (
                                        <Form.Item name={e.name} key={e.name} label={e.label}>
                                            <Input placeholder={e.placeholder || `请输入${e.label}`} />
                                        </Form.Item>
                                    )
                                default:
                                    return ''
                            }
                        })
                    }
                    <div style={{
                        width:'100%',
                        marginTop: '20px'
                    }}>
                        <Form.Item colon={false} label={''}>
                            <Button  type="primary" htmlType="submit">搜索</Button>
                            <Button onClick={this.handleReset} type="link">清除筛选项</Button>
                        </Form.Item>
                    </div>
                </Form>
            </>
        )
    }
}
